package com.bw.finance.controller;


import com.bw.finance.conf.ResponseResult;
import com.bw.finance.eneity.locana.EbankLoanInfo;
import com.bw.finance.eneity.locana.res.Borrowinfo;
import com.bw.finance.eneity.user.EbankBorrower;
import com.bw.finance.eneity.user.EbankInvestor;
import com.bw.finance.service.IEbankLoanInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lizhengqian
 * @since 2020-08-18
 */
@RestController
@RequestMapping("/loan")
public class EbankLoanInfoController {

    @Resource
    private IEbankLoanInfoService infoService;

    /**
     * 新增借款人
     * @return
     */
    @PostMapping("/Addloan")
    public ResponseResult Addloan(@RequestBody Borrowinfo borrowinfo) {
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            result=infoService.addloan(borrowinfo);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("保存失败"+e.toString());
        }
        return result;
    }

    //查询借款的信息
    @PostMapping("list/{pagenum}/{pagesize}")
    public ResponseResult invlist(@PathVariable int pagenum , @PathVariable int pagesize, @RequestBody EbankLoanInfo ebankLoanInfo){
        return infoService.invlist(pagenum,pagesize,ebankLoanInfo);
    }

    //审核状态修改
    @PostMapping("updatestate/{id}/{val}")
    public ResponseResult updatestate(@PathVariable String id , @PathVariable int val ){
        return infoService.updatestate(id,val);
    }

    //    借款信息对象
    @PostMapping("findone/{id}")
    public ResponseResult findone(@PathVariable int id ){
        return infoService.findone(id);
    }

    @PostMapping("newlist/{pagenum}/{pagesize}")
    public ResponseResult newlist(@PathVariable int pagenum , @PathVariable int pagesize, @RequestBody EbankLoanInfo ebankLoanInfo){
        return infoService.newlist(pagenum,pagesize,ebankLoanInfo);
    }

    @GetMapping("findform/{loanid}")
    public ResponseResult findform(@PathVariable Long loanid){
        return infoService.findform(loanid);
    }

    @PostMapping("/updateloan/{id}")
    public ResponseResult updateloan(@RequestBody EbankLoanInfo loanInfo,@PathVariable Long id) {
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            infoService.updateloan(loanInfo,id);
            result.setMessage("修改成功！！！");
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("保存失败"+e.toString());
        }
        return result;
    }

    /**
     * 获取还款记录的借款信息
     */
    @PostMapping("/getBorrowerList/{pagenum}/{pagesize}")
    public ResponseResult getBorrowerList(@PathVariable("pagenum") int pagenum, @PathVariable("pagesize") int pagesizes, @RequestBody EbankBorrower ebankBorrower){
        ResponseResult result = ResponseResult.SUCCESS();
        try {
            result = infoService.getBorrowerList(pagenum,pagesizes,ebankBorrower);
        }catch (Exception e){
            result.setMessage("查询失败");
            result.setSuccess(false);
            e.printStackTrace();
        }
        return result;
    }
}
